{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "tags": [],
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "#load \"LoadBaseToolWPF.csx\"\n",
    "\n",
    "using BaseTool;\n",
    "using BaseHSMSTool;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Binary 相关\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建 Binary\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b01010101\n",
      "0b00000000\n"
     ]
    }
   ],
   "source": [
    "Binary _binary1 = new Binary(0b01010101);\n",
    "Binary _binary2 = new Binary(256);\n",
    "_binary1.Dump();\n",
    "_binary2.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "获取 Binary 的位\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\r\n"
     ]
    }
   ],
   "source": [
    "Binary _binary = new Binary(0b_0101_0101);\n",
    "_binary[0].Dump();  // 输出1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ToString 方法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b11010101\n",
      "0xD5\n"
     ]
    }
   ],
   "source": [
    "Binary _binary = new Binary(0b11010101);\n",
    "Console.WriteLine(_binary.ToString());\n",
    "Console.WriteLine(_binary.ToString(\"X2\"));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Binary 和 byte 类型转换\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Binary _binary = 1;  // 调用隐式类型转换:0b_0000_0001\n",
    "byte _byte = (byte)_binary;   // 调用显示类型转换:1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Binary 数据对比\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "Binary _binary1 = 1;\n",
    "Binary _binary2 = 1;\n",
    "Binary _binary3 = 0;\n",
    "\n",
    "(_binary1 == _binary2).Dump();  // true\n",
    "(_binary1 == _binary3).Dump();  // false\n",
    "(_binary1 == 1).Dump();         // true，和byte数据的对比\n",
    "(_binary1 == 0).Dump();         // false，和byte数据的对比"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Binary 序列化\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"0b11010101\"\n",
      "0b11010101\n"
     ]
    }
   ],
   "source": [
    "Binary _binary1 = 0b11010101;\n",
    "string _json_string = BaseFunction.TransToJsonString(_binary1);\n",
    "Binary _binary2 = BaseFunction.TransFromJsonString<Binary>(_json_string);\n",
    "\n",
    "// 序列化的时候使用双引号包裹\n",
    "Console.WriteLine(_json_string);\n",
    "Console.WriteLine(_binary2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SECSItem 相关\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建二进制 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n",
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\",\"0b10101010\"]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item11 = new SECSItem((Binary)0b_1010_1010);\n",
    "_item11.Dump();\n",
    "\n",
    "SECSItem _item12 = new SECSItem((Binary)0b_1010_1010, (Binary)0b_1010_1010);\n",
    "_item12.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建布尔型 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Boolean\",\"mData\":[true]}\n",
      "{\"mType\":\"Boolean\",\"mData\":[true,false]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = new SECSItem(true);\n",
    "_item1.Dump();\n",
    "\n",
    "SECSItem _item2 = new SECSItem(true, false);\n",
    "_item2.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "source": [
    "创建整型 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Int8\",\"mData\":[127]}\n",
      "{\"mType\":\"Int32\",\"mData\":[255,256]}\n",
      "{\"mType\":\"Int64\",\"mData\":[255,256]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item21 = new SECSItem((sbyte)127);\n",
    "_item21.Dump();\n",
    "\n",
    "SECSItem _item22 = new SECSItem(255, 256);\n",
    "_item22.Dump();\n",
    "\n",
    "SECSItem _item23 = new SECSItem(255, (long)256);\n",
    "_item23.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建浮点型 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Float32\",\"mData\":[23.4]}\n",
      "{\"mType\":\"Float64\",\"mData\":[23.4]}\n",
      "{\"mType\":\"Float64\",\"mData\":[23.399999618530273,32.4]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item31 = new SECSItem(23.4f);\n",
    "_item31.Dump();\n",
    "\n",
    "SECSItem _item32 = new SECSItem(23.4);\n",
    "_item32.Dump();\n",
    "\n",
    "SECSItem _item33 = new SECSItem(23.4f, 32.4);\n",
    "_item33.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建字符串 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"ASCII\",\"mData\":[\"Hello World\"]}\n",
      "{\"mType\":\"Unicode\",\"mData\":[\"中文测试\"]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"ASCII\",\"mData\":[\"Hello World\"]},{\"mType\":\"Unicode\",\"mData\":[\"中文测试\"]}]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item41 = new SECSItem(\"Hello World\");\n",
    "_item41.Dump();\n",
    "\n",
    "SECSItem _item42 = new SECSItem(\"中文测试\");\n",
    "_item42.Dump();\n",
    "\n",
    "SECSItem _item43 = new SECSItem(\"Hello World\" ,\"中文测试\");\n",
    "_item43.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "创建列表 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b00001111\"]},{\"mType\":\"Boolean\",\"mData\":[false]}]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Int32\",\"mData\":[1]},{\"mType\":\"Int32\",\"mData\":[2]}]}\n",
      "{\"mType\":\"List\",\"mData\":[]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item51 = new SECSItem((Binary)0b0000_1111, false);\n",
    "_item51.Dump();\n",
    "\n",
    "SECSItem _item52 = new SECSItem((SECSItem)1, (SECSItem)2);\n",
    "_item52.Dump();\n",
    "\n",
    "SECSItem _item53 = SECSItem.EmptyList;\n",
    "_item53.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n",
      "{\"mType\":\"Int32\",\"mData\":[10]}\n",
      "{\"mType\":\"Float64\",\"mData\":[23.4]}\n",
      "{\"mType\":\"ASCII\",\"mData\":[\"Hello World\"]}\n",
      "{\"mType\":\"Boolean\",\"mData\":[true]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = 10;\n",
    "SECSItem _item3 = 23.4;\n",
    "SECSItem _item4 = \"Hello World\";\n",
    "SECSItem _item5 = true;\n",
    "\n",
    "_item1.Dump();\n",
    "_item2.Dump();\n",
    "_item3.Dump();\n",
    "_item4.Dump();\n",
    "_item5.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b10101010\n",
      "10\n",
      "23.4\n",
      "Hello World\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = 10;\n",
    "SECSItem _item3 = 23.4;\n",
    "SECSItem _item4 = \"Hello World\";\n",
    "SECSItem _item5 = true;\n",
    "\n",
    "Binary _binary = (Binary)(_item1) ;\n",
    "int _int = (int)_item2;\n",
    "double _float = (double)_item3;\n",
    "string _string = (string)_item4;\n",
    "bool _bool = (bool)_item5;\n",
    "\n",
    "_binary.Dump();\n",
    "_int.Dump();\n",
    "_float.Dump();\n",
    "_string.Dump();\n",
    "_bool.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "获取 SECSItem 的长度\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = new SECSItem(10, 20);\n",
    "SECSItem _item3 = new SECSItem(new SECSItem(10), new SECSItem(20));\n",
    "\n",
    "_item1.Count.Dump();\n",
    "_item2.Count.Dump();\n",
    "_item3.Count.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "索引访问 SECSItem\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n",
      "{\"mType\":\"Int32\",\"mData\":[10]}\n",
      "{\"mType\":\"Int32\",\"mData\":[20]}\n",
      "{\"mType\":\"Int32\",\"mData\":[10]}\n",
      "{\"mType\":\"Int32\",\"mData\":[20]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = new SECSItem(10, 20);\n",
    "SECSItem _item3 = new SECSItem(new SECSItem(10), new SECSItem(20));\n",
    "\n",
    "SECSItem _item11 = _item1[0];\n",
    "SECSItem _item21 = _item2[0];\n",
    "SECSItem _item22 = _item2[1];\n",
    "SECSItem _item31 = _item3[0];\n",
    "SECSItem _item32 = _item3[1];\n",
    "\n",
    "_item11.Dump();\n",
    "_item21.Dump();\n",
    "_item22.Dump();\n",
    "_item31.Dump();\n",
    "_item32.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "迭代访问\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n",
      "{\"mType\":\"Int32\",\"mData\":[10]}\n",
      "{\"mType\":\"Int32\",\"mData\":[20]}\n",
      "{\"mType\":\"Int32\",\"mData\":[10]}\n",
      "{\"mType\":\"Int32\",\"mData\":[20]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = new SECSItem(10, 20);\n",
    "SECSItem _item3 = new SECSItem(new SECSItem(10), new SECSItem(20));\n",
    "\n",
    "foreach (SECSItem _item in _item1) { _item.Dump(); }\n",
    "foreach (SECSItem _item in _item2) { _item.Dump(); }\n",
    "foreach (SECSItem _item in _item3) { _item.Dump(); }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数组转换为列表\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Int32\",\"mData\":[10]},{\"mType\":\"Int32\",\"mData\":[20]}]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Int32\",\"mData\":[10]},{\"mType\":\"Int32\",\"mData\":[20]}]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = new SECSItem(10, 20);\n",
    "SECSItem _item3 = new SECSItem(new SECSItem(10), new SECSItem(20));\n",
    "\n",
    "SECSItem _item_list1 = _item1.ToSECSList();\n",
    "SECSItem _item_list2 = _item2.ToSECSList();\n",
    "SECSItem _item_list3 = _item3.ToSECSList();\n",
    "\n",
    "_item_list1.Dump();\n",
    "_item_list2.Dump();\n",
    "_item_list3.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据比较\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "SECSItem _item2 = new SECSItem(10, 20);\n",
    "SECSItem _item3 = new SECSItem(new SECSItem(10), new SECSItem(20));\n",
    "\n",
    "_item1.Equals(new SECSItem((Binary)0b_1010_1010)).Dump();\n",
    "_item2.Equals(new SECSItem(10, 20)).Dump();\n",
    "_item3.Equals(new SECSItem(new SECSItem(10), new SECSItem(20))).Dump();\n",
    "\n",
    "(_item1 == new SECSItem((Binary)0b_1010_1010)).Dump();\n",
    "(_item2 == new SECSItem(10, 20)).Dump();\n",
    "(_item3 == new SECSItem(new SECSItem(10), new SECSItem(20))).Dump();\n",
    "\n",
    "(_item1 == null).Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据大小比较\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = true;\n",
    "SECSItem _item2 = false;\n",
    "\n",
    "(_item1 > _item2).Dump();\n",
    "(_item1 < _item2).Dump();\n",
    "\n",
    "SECSItem _item3 = 10;\n",
    "SECSItem _item4 = 10;\n",
    "SECSItem _item5 = 20;\n",
    "\n",
    "(_item3 < _item4).Dump();\n",
    "(_item3 < _item5).Dump();\n",
    "(_item3 <= _item4).Dump();\n",
    "(_item3 <= _item5).Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最小值/最大值/默认值\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"ASCII\",\"mData\":[\"\"]}\n",
      "{\"mType\":\"Unicode\",\"mData\":[\"\"]}\n",
      "{\"mType\":\"Int8\",\"mData\":[-128]}\n",
      "{\"mType\":\"Int8\",\"mData\":[127]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = SECSItem.Default(SECSItemType.ASCII);\n",
    "SECSItem _item2 = SECSItem.Default(SECSItemType.Unicode);\n",
    "SECSItem _item3 = SECSItem.Minimum(SECSItemType.Int8);\n",
    "SECSItem _item4 = SECSItem.Maximum(SECSItemType.Int8);\n",
    "\n",
    "_item1.Dump();\n",
    "_item2.Dump();\n",
    "_item3.Dump();\n",
    "_item4.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "和字节数组之间的相互转换\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年04月19日 15:05:50  Debug\n",
      "----Message：格式输出 byte 数组\n",
      "----|  DEC |  HEX |       Bin |\n",
      "----| ---- | ---- | --------- |\n",
      "----|   33 |   21 | 0010-0001 |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|  170 |   AA | 1010-1010 |\n",
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n",
      "{\"mType\":\"Binary\",\"mData\":[\"0b10101010\"]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = (Binary)0b_1010_1010;\n",
    "BaseTransform.FormatShowArray(_item1.ByteFormat);\n",
    "\n",
    "SECSItem _item11 = SECSItem.Parse(_item1.ByteFormat);\n",
    "_item1.Dump();\n",
    "_item11.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年04月19日 15:05:50  Debug\n",
      "----Message：格式输出 byte 数组\n",
      "----|  DEC |  HEX |       Bin |\n",
      "----| ---- | ---- | --------- |\n",
      "----|   65 |   41 | 0100-0001 |\n",
      "----|    3 |   03 | 0000-0011 |\n",
      "----|   65 |   41 | 0100-0001 |\n",
      "----|   66 |   42 | 0100-0010 |\n",
      "----|   67 |   43 | 0100-0011 |\n",
      "{\"mType\":\"ASCII\",\"mData\":[\"ABC\"]}\n",
      "{\"mType\":\"ASCII\",\"mData\":[\"ABC\"]}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "SECSItem _item2 = \"ABC\";\n",
    "BaseTransform.FormatShowArray(_item2.ByteFormat);\n",
    "\n",
    "SECSItem _item21 = SECSItem.Parse(_item2.ByteFormat);\n",
    "_item2.Dump();\n",
    "_item21.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年04月19日 15:05:50  Debug\n",
      "----Message：格式输出 byte 数组\n",
      "----|  DEC |  HEX |       Bin |\n",
      "----| ---- | ---- | --------- |\n",
      "----|  105 |   69 | 0110-1001 |\n",
      "----|    6 |   06 | 0000-0110 |\n",
      "----|    0 |   00 | 0000-0000 |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|    0 |   00 | 0000-0000 |\n",
      "----|    2 |   02 | 0000-0010 |\n",
      "----|    0 |   00 | 0000-0000 |\n",
      "----|    3 |   03 | 0000-0011 |\n",
      "{\"mType\":\"Int16\",\"mData\":[1,2,3]}\n",
      "{\"mType\":\"Int16\",\"mData\":[1,2,3]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item3 = new SECSItem((short)1, (short)2, (short)3);\n",
    "BaseTransform.FormatShowArray(_item3.ByteFormat);\n",
    "\n",
    "SECSItem _item31 = SECSItem.Parse(_item3.ByteFormat);\n",
    "_item3.Dump();\n",
    "_item31.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年04月19日 15:05:50  Debug\n",
      "----Message：格式输出 byte 数组\n",
      "----|  DEC |  HEX |       Bin |\n",
      "----| ---- | ---- | --------- |\n",
      "----|  145 |   91 | 1001-0001 |\n",
      "----|    4 |   04 | 0000-0100 |\n",
      "----|   66 |   42 | 0100-0010 |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|  153 |   99 | 1001-1001 |\n",
      "----|  154 |   9A | 1001-1010 |\n",
      "{\"mType\":\"Float32\",\"mData\":[32.4]}\n",
      "{\"mType\":\"Float32\",\"mData\":[32.4]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item4 = new SECSItem(32.4f);\n",
    "BaseTransform.FormatShowArray(_item4.ByteFormat);\n",
    "\n",
    "SECSItem _item41 = SECSItem.Parse(_item4.ByteFormat);\n",
    "_item4.Dump();\n",
    "_item41.Dump();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年04月19日 15:05:50  Debug\n",
      "----Message：格式输出 byte 数组\n",
      "----|  DEC |  HEX |       Bin |\n",
      "----| ---- | ---- | --------- |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|    3 |   03 | 0000-0011 |\n",
      "----|   33 |   21 | 0010-0001 |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|    4 |   04 | 0000-0100 |\n",
      "----|  101 |   65 | 0110-0101 |\n",
      "----|    1 |   01 | 0000-0001 |\n",
      "----|   17 |   11 | 0001-0001 |\n",
      "----|   65 |   41 | 0100-0001 |\n",
      "----|    7 |   07 | 0000-0111 |\n",
      "----|   84 |   54 | 0101-0100 |\n",
      "----|   49 |   31 | 0011-0001 |\n",
      "----|   32 |   20 | 0010-0000 |\n",
      "----|   72 |   48 | 0100-1000 |\n",
      "----|   73 |   49 | 0100-1001 |\n",
      "----|   71 |   47 | 0100-0111 |\n",
      "----|   72 |   48 | 0100-1000 |\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b00000100\"]},{\"mType\":\"Int8\",\"mData\":[17]},{\"mType\":\"ASCII\",\"mData\":[\"T1 HIGH\"]}]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b00000100\"]},{\"mType\":\"Int8\",\"mData\":[17]},{\"mType\":\"ASCII\",\"mData\":[\"T1 HIGH\"]}]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item5 = new SECSItem((Binary)4, (sbyte)17, \"T1 HIGH\");\n",
    "BaseTransform.FormatShowArray(_item5.ByteFormat);\n",
    "\n",
    "SECSItem _item51 = SECSItem.Parse(_item5.ByteFormat);\n",
    "_item5.Dump();\n",
    "_item51.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "和 json 字符串之间的相互转换\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b00000100\"]},{\"mType\":\"Int8\",\"mData\":[17]},{\"mType\":\"ASCII\",\"mData\":[\"T1 HIGH\"]}]}\n",
      "{\"mType\":\"List\",\"mData\":[{\"mType\":\"Binary\",\"mData\":[\"0b00000100\"]},{\"mType\":\"Int8\",\"mData\":[17]},{\"mType\":\"ASCII\",\"mData\":[\"T1 HIGH\"]}]}\n"
     ]
    }
   ],
   "source": [
    "SECSItem _item1 = new SECSItem((Binary)4, (sbyte)17, \"T1 HIGH\");\n",
    "string _string = _item1.ToString();\n",
    "SECSItem _item2 = SECSItem.Parse(_string);\n",
    "\n",
    "_item1.Dump();\n",
    "_item2.Dump();"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "csharp"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
